package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.Strategy;
import cn.wolfcode.trip.base.domain.StrategyCatalog;
import cn.wolfcode.trip.base.domain.StrategyDetail;
import cn.wolfcode.trip.base.query.StrategyQuery;
import cn.wolfcode.trip.base.service.IStrategyCatalogService;
import cn.wolfcode.trip.base.service.IStrategyDetailService;
import cn.wolfcode.trip.base.service.IStrategyService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/strategies")
public class StrategyController {
    @Autowired
    private IStrategyService strategyService;
    @Autowired
    private IStrategyCatalogService catalogService;
    @Autowired
    private IStrategyDetailService detailService;
    @GetMapping
    public PageInfo list(StrategyQuery qo){
        return strategyService.query(qo);
    }

    /**
     * 根据大攻略的Id去查攻略
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Strategy getById(@PathVariable Long id){
        return strategyService.getById(id);
    }

    /**
     * 根据大攻略的id去查攻略分类
     * @param id
     * @return
     */
    @GetMapping("/{id}/catalogs")
    public List<StrategyCatalog> listCatalogsByStrategyId(@PathVariable Long id){
        return catalogService.listByStrategyId(id);
    }

    @GetMapping("/details/{id}")
    public StrategyDetail getDetailById(@PathVariable Long id){
        return detailService.getDetailById(id);
    }
}
